<?

if ($DATA['component']['id']) {

	// list editor
	
	$_id_component	= $DATA['component']['id'];			//	list id value
	$_id_data		= D_MB_DATA;			//	meta id value
	$_id_meta		= D_MB_META;			//	meta id value

	$_crit = "id_data=$_id_data AND id_parent=$_id_component";

	$_param			= 'edit';				//	ID param name in the URL, used here & @ template
	
	$_fields = array(
		'title' => array('lang' => true), 
		'article' => array('lang' => true), 
		'body' => array('large' => true, 'lang' => true),
	);

	$s = array_extend( array('w' => 800, 'h' => 600, 'param' => 'id',
			'template' => '<iframe width="{w}" height="{h}" src="http://www.youtube.com/embed/{id}?rel=0" frameborder="0" allowfullscreen></iframe>', 
			'nav' => 0, 'navigator' => 1, 'circular' => 0, 'autoscroll' => 0, 'show_title' => 0, 'show_descr' => 0, 'caption' => ''), $DATA['component']['settings']);
	
	
	if (($a = (int)param('edit')) && ($DATA['object'] = datafetch('db_item', tb('data'), "$_crit AND id=$a"))) {
	
		switch (action(array('editor_save', 'editor_save_enable'))) {
		
			case 'editor_save_enable':
			
				$DATA['object']['attr'] |= AA_VISIBLE;
			
			case 'editor_save':

				$_record = array('id_data' => $_id_meta, 'id_parent' => $a);
	
				dataset('killmeta', "id_data=$_id_meta AND id_parent=$a");
				dataset('savemeta', prepareModel($_fields, $_record));

				$t = ($temp = trim($_POST['title'][LANG_DEF])) ? $temp : $DATA['object']['title'];
				dataset('db_update', tb('data'), array('name' => $t, 'attr' => $DATA['object']['attr']), "id=$a");
				
				header("Location: "._transformURL($CURRENT->url, array('remove_param' => $_param)));
				exit;
		
				break;
		}
	
	
		$DATA['object'] = array_merge($DATA['object'], datafetch_array('loadmeta', $_id_meta, 
			array('parent' => $a, 'getclob' => true)));
	
		foreach($DATA['langs'] as $lang)
			$DATA['object']['data'][$lang['text']] = datafetch_array('loadmeta', $_id_meta, 
				array('parent' => $a, 'assoc' => $lang['text'], 'getclob' => true));
	
		$DATA['object']['image'] = checkImage(FP_UPLOAD_PATH.$s['path'], $a);
	}

	return false;
	
} else exit;